import 'dart:convert';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/AppConfig/Config.dart';
import 'package:sph_shipper/SendGoods/TMSAddressSelection.dart';

import '../AppConfig/LocalStorage.dart';
import '../AppConfig/RouteAct.dart';
import '../http/NoLoadingGetApi.dart';
import '../http/NoLoadingPostApi.dart';
import '../http/api.dart';
import 'CargoInformation.dart';
import 'LoadingAddressView.dart';

class PublishEnterpriseGoods extends StatefulWidget {
  const PublishEnterpriseGoods({super.key});

  @override
  State<PublishEnterpriseGoods> createState() => _PublishEnterpriseGoodsState();
}

class _PublishEnterpriseGoodsState extends State<PublishEnterpriseGoods> {
  int goodsType=2;
  String Organization="请选择组织名称";
  String projectName="请选择项目名称";
  String startAddress="请填写装货地详细地址";
  String endAddress="请填写卸货地详细地址";
  String startAddressTwo="请填写装货地详细地址";
  String endAddressTwo="请填写卸货地详细地址";
  List startAddressList=[];
  List endAddressList=[];
  List packList=['纸箱',"散装","托盘","捆扎","裸装","袋装","吨包","更多>"];
  List morePackList=['纸箱',"散装","托盘","捆扎","裸装","袋装","吨包","木箱","桶装","架子","周转箱","线盘","罐装","压块","泡沫箱","水箱","网兜","笼装","筐装","其他"];
  String packType="";
  String startTime="请选择";
  int isMore=0;
  String settlementStr="请选择";
  String goodsMessage = "";
  String parentDictValue = "1700";
  List goodsMessageList=["","","","",""];
  String startCitynameOne ="";
  List startCitycodeOne =[];
  String endCitynameOne ="";
  List endCitycodeOne =[];
  List startAddressOne=[];
  List endAddressOne=[];
  String detailAddressOne="";
  String detailAddressThree="";
  Map startLocationOne={};
  Map endLocationOne={};
  String dintanceStr="";
  String goodsName="";
  Map orgMap={};
  String orderNum="";
  int GoodsListNum=0;
  Map userInfo={};
  Map projectMap={};
  int schedulingIndex=-1;
  List scheduNameList=["王二二(18888888888)","王二二(18888888888)","王二二(18888888888)","王二二(18888888888)","王二二(18888888888)","王二二(18888888888)"];

  //获取距离
  Future<void> getDistanceAction() async {

    String? token = await TokenManager.getToken();
    dio.interceptors.add(InterceptorsWrapper(
        onRequest: (options, handler) {
          options.headers["satoken"] = token;
          return handler.next(options);
        }
    ));
    dio.get<String>("https://api.map.baidu.com/directionlite/v1/driving?origin=${startLocationOne['lat']},${startLocationOne['lng']}&destination=${endLocationOne['lat']},${endLocationOne['lng']}&ak=0t6rhRWUGmqtbsMRMBVSqzbBwBrCzXLj")
        .then((r) {
      setState(() {
        print(r);
        Map<String, dynamic> jsonMap = json.decode(r.toString());
        // 获取code和data
        String code = jsonMap['status'].toString();
        if (code == "0") {
          setState(() {
            List list =jsonMap['result']['routes'];
            dintanceStr = list[0]['distance'].toString();
          });
        } else {

        }
        // 打印结果
        print('Code: $code');
      });
    }).catchError((error) {
      print(error);
    });

  }
  void geuUserInfo(){
    NoLoadinggetApiManager.getData(
      context,
      MyServiceUrl.getLoginUser,
      {},
          (responseData) async {
            userInfo=responseData['data'];
            Organization=userInfo['companyInfo']['name'];
      },
    );
  }
  void initState() {
    super.initState();
    geuUserInfo();

  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Column(
      children: [
        Expanded(child: ListView(
          children: [
          // Container(
          //   margin: EdgeInsets.only(top: 8.h),
          //   width: screenSize.width,height:30.h,
          //   decoration: BoxDecoration(
          //     color: Colors.white,
          //     image: DecorationImage(
          //       image: goodsType==1? AssetImage('lib/Images/OrderList/企业发货快速找车bg.png'):AssetImage('lib/Images/OrderList/企业发货普通模式bg.png'),
          //       fit: BoxFit.cover,
          //     ),
          //   ),
          //   child: Row(
          //     children: [
          //       GestureDetector(
          //         child:   Container(
          //           width: screenSize.width/2,
          //           child:Center(child:Text("快速找车模式",style: TextStyle(color:goodsType==1? MyColors.themeColor:Colors.black,fontWeight: goodsType==1?FontWeight.w600:FontWeight.w300,fontSize: 14.sp),),
          //           ),),
          //         onTap: (){
          //           setState(() {
          //             goodsType=1;
          //           });
          //         },
          //       ),
          //       GestureDetector(
          //         child:   Container(
          //           width: screenSize.width/2,
          //           child:Center(child:
          //           Text("普通模式",style: TextStyle(color:goodsType==2? MyColors.themeColor:Colors.black,fontWeight: goodsType==2?FontWeight.w600:FontWeight.w300,fontSize: 14.sp),),
          //           ),),
          //         onTap: (){
          //           setState(() {
          //             goodsType=2;
          //           });
          //         },
          //       ),
          //     ],
          //   ),
          // ),
            goodsType==1?
                Column(
                  children: [
                    GestureDetector(
                      child:   Container(
                        margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                        padding: EdgeInsets.only(top: 8.h,bottom: 8.h,left: 10.w,right: 10.w),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(Radius.circular(10))),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text("*",style: TextStyle(color: MyColors.themeColor),),
                                Text("组织",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              ],
                            ),
                          Row(
                            children: [
                              Text(projectName,style: TextStyle(color:projectName=="请选择项目名称"? MyColors.hintColor:Colors.black,fontSize: 14.sp),),
                              SizedBox(width: 4.w,),
                              // Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                            ],
                          ),
                          ],
                        ),
                      ),
                     
                    ),
                  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                    padding: EdgeInsets.only(top: 27.h,bottom: 27.h,left: 20.w,right: 7.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Column(
                      children: [
                        GestureDetector(
                          child:   Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height: 20.h,),
                                  SizedBox(width:13.w ,),
                                  Container(
                                    width: screenSize.width/1.5,
                                    child: Text(startAddress=="请填写装货地详细地址"?startAddress:"$startCitynameOne\n$startAddress",style: TextStyle(color: startAddress=="请填写装货地详细地址"?MyColors.hintColor:Colors.black,fontSize: 14.sp),),

                                  ),

                                ],
                              ),
                              Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),

                            ],
                          ),
                          onTap: ()async{
                            final result = await  Navigator.push( context, FadeRoute(page:LoadingAddressView(addressType: 2, query: startAddressOne.isNotEmpty?startAddressOne[1]:"",)));
                            if(result!=null){
                              setState(() {
                                startCitynameOne=result['province']+" "+result['city']+" "+result['district'];
                                startCitycodeOne=[result['adcode'].substring(0, 2)+"0000",result['adcode'].substring(0, 4)+"00",result['adcode']];
                                startAddressOne=[result['province'],result['city'],result['district']];
                                startAddress=result['address'];
                                startLocationOne=result['location'];
                                if(detailAddressOne!=""&&detailAddressThree!=""){
                                  getDistanceAction();
                                }
                              });

                            }
                          },
                        ),
                        Divider(height: 34.h,color: MyColors.backgreyColor,),
                        GestureDetector(
                          child:   Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height: 20.h,),
                                  SizedBox(width:13.w ,),
                                  Container(
                                    width: screenSize.width/1.5,
                                    child: Text(endAddress=="请填写卸货地详细地址"?endAddress:"$endCitynameOne\n$endAddress",style: TextStyle(color: endAddress=="请填写卸货地详细地址"?MyColors.hintColor:Colors.black,fontSize: 14.sp),),


                                  ),
                                ],
                              ),
                              Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                            ],
                          ),
                          onTap: ()async{
                            final result = await  Navigator.push( context, FadeRoute(page:LoadingAddressView(addressType: 2, query: endAddressOne.isNotEmpty?endAddressOne[1]:"",)));
                            if(result!=null){
                              setState(() {
                                endCitynameOne=result['province']+" "+result['city']+" "+result['district'];
                                endCitycodeOne=[result['adcode'].substring(0, 2)+"0000",result['adcode'].substring(0, 4)+"00",result['adcode']];
                                endAddressOne=[result['province'],result['city'],result['district']];
                                endAddress=result['address'];
                                endLocationOne=result['location'];
                                if(detailAddressOne!=""&&detailAddressThree!=""){
                                  getDistanceAction();
                                }
                              });

                            }
                          },
                        ),
                      ],
                    ),
                  ),
                    Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(top: 17.h,bottom: 18.h,left: 20.w,right: 14.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child: Column(
                        children: [
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Text("*",style: TextStyle(color: MyColors.themeColor),),
                                  Text("货物名称",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                ],
                              ),
                              Container(
                                width: screenSize.width-150.w,
                                height: 30.h,
                                child:  TextField(
                                  decoration: InputDecoration(
                                    hintText: '请输入',
                                    hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                                    filled: true,
                                    fillColor: Colors.white,
                                    border: InputBorder.none,
                                    alignLabelWithHint: true,
                                  ),
                                  textAlign: TextAlign.right,
                                  style: TextStyle(color: Colors.black),
                                  onChanged: (value) {
                                    setState(() {
                                      goodsName=value;
                                    });
                                  },
                                ),
                              ),
                            ],
                          ),
                          Divider(height:27.h ,color: MyColors.backgreyColor,),
                          Row(
                            children: [
                              Text("*",style: TextStyle(color: MyColors.themeColor),),
                              Text("包装方式",style: TextStyle(color: Colors.black),),
                            ],
                          ),
                          SizedBox(height: 8.h,),
                          Wrap(
                            spacing: 8.0, // 两个Container之间的水平间距
                            runSpacing: 10.0, // 行与行之间的垂直间距
                            children: isMore==0?
                            packList.map((length) {
                              bool isSelected = packType.contains(length)?? false;
                              return GestureDetector(
                                onTap: () {
                                  // 处理点击事件
                                  setState(() {
                                    if (isSelected) {
                                      // 如果已经被选中，则移除
                                      packType="";
                                    } else {
                                      if(length=="更多>")
                                        isMore=1;
                                        else
                                      packType=length;
                                    }
                                  });
                                },
                                child: Container(
                                  width: 80.0, // Container宽度
                                  height: 30.0, // Container高度，使其成为正方形
                                  decoration: BoxDecoration(
                                    color: isSelected ? Color.fromRGBO(251, 236, 228, 1) : MyColors.backgreyColor, // 根据状态决定颜色
                                    borderRadius: BorderRadius.circular(3.0), // 设置Container的圆角
                                  ),
                                  child: Center(
                                    child: Text(
                                      length,
                                      style: TextStyle(
                                        fontSize: 14.sp,
                                        color: isSelected ?MyColors.themeColor:MyColors.textColor, // 文字颜色为白色
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            }).toList():
                            morePackList.map((length) {
                              bool isSelected = packType.contains(length)?? false;
                              return GestureDetector(
                                onTap: () {
                                  // 处理点击事件
                                  setState(() {
                                    if (isSelected) {
                                      // 如果已经被选中，则移除
                                      packType="";
                                    } else {
                                        packType=length;
                                    }
                                  });
                                },
                                child: Container(
                                  width: 80.0, // Container宽度
                                  height: 30.0, // Container高度，使其成为正方形
                                  decoration: BoxDecoration(
                                    color: isSelected ? Color.fromRGBO(251, 236, 228, 1) : MyColors.backgreyColor, // 根据状态决定颜色
                                    borderRadius: BorderRadius.circular(3.0), // 设置Container的圆角
                                  ),
                                  child: Center(
                                    child: Text(
                                      length,
                                      style: TextStyle(
                                        fontSize: 14.sp,
                                        color: isSelected ?MyColors.themeColor:MyColors.textColor, // 文字颜色为白色
                                      ),
                                    ),
                                  ),
                                ),
                              );
                            }).toList(),
                          ),
                        ],
                      ),
                    ),
                  ],
                ):
                Column(
                  children: [
                    Container(
                      padding: EdgeInsets.only(left: 20.w,top: 16.h,right: 7.w,bottom: 14.h),
                      margin: EdgeInsets.only(top: 8.h,right: 10.w,left: 10.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child: Column(
                        children: [
                          GestureDetector(
                            child:  Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Text("*",style: TextStyle(color: MyColors.themeColor),),
                                    Text("组织",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                  ],
                                ),
                                Row(
                                  children: [
                                    Text(Organization,style: TextStyle(color:Organization=="请选择组织名称"? MyColors.hintColor:Colors.black,fontSize: 14.sp),),
                                    SizedBox(width: 4.w,),
                                    // Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                                  ],
                                ),
                              ],
                            ),
                            onTap: ()async{
                              final result=await showModalBottomSheet(context: context, builder: (BuildContext context) {
                                return chooseOrganizationsheet( name: Organization,);
                              });
                              if (result!=null){
                                setState(() {
                                  Organization=result[0];
                                  orgMap=result[1];
                                });

                              }
                            },
                          ),

                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  Text("*",style: TextStyle(color: MyColors.themeColor),),
                                  Text("运单号",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                ],
                              ),
                              Container(
                                width: screenSize.width-150.w,
                                height: 30.h,
                                child:  TextField(
                                  decoration: InputDecoration(
                                    hintText: '请输入',
                                    hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
                                    filled: true,
                                    fillColor: Colors.white,
                                    border: InputBorder.none,
                                    alignLabelWithHint: true,
                                  ),
                                  textAlign: TextAlign.right,
                                  style: TextStyle(color: Colors.black),
                                  onChanged: (value) {
                                    setState(() {
                                      orderNum=value;
                                    });
                                  },
                                ),
                              ),
                            ],
                          ),
                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                          GestureDetector(
                            child:Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Text("*",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                                    Text("调度员",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                  ],
                                ),

                                Row(
                                  children: [
                                    schedulingIndex!=-1?
                                    Text(scheduNameList[schedulingIndex],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                    Text("请选择",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                    Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                                  ],
                                ),

                              ],
                            ),
                            onTap: (){
                              showModalBottomSheet(
                                  context: context,
                                  builder: (BuildContext context) {
                                    return Container(
                                        width: screenSize.width,
                                        padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 15.h),
                                        decoration: BoxDecoration(
                                          borderRadius: BorderRadius.all(Radius.circular(6)),
                                          color: Colors.white,
                                        ),
                                        child: Column(
                                          children: [
                                            Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                SizedBox(width: 30,),
                                                Text("请选择调度员",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                                                GestureDetector(
                                                  child: Icon(Icons.close,color: MyColors.textColor,size: 30,),
                                                  onTap: (){Navigator.pop(context);},
                                                )
                                              ],
                                            ),
                                            Divider(height: 20.h,color: MyColors.backgreyColor,),
                                            Container(
                                                height: 35.h,
                                                margin: EdgeInsets.only(top: 8.h,bottom: 4.h,left: 10.w,right: 10.w),
                                                padding: EdgeInsets.only(left: 8.w),
                                                decoration: BoxDecoration(
                                                    color:MyColors.backgreyColor,
                                                    borderRadius: BorderRadius.all(Radius.circular(5))),
                                                child:Row(
                                                    children: [
                                                      Icon(Icons.search,color: MyColors.authTipColor,),
                                                      Container(
                                                        height: 35.h,
                                                        width:screenSize.width-100.w,
                                                        decoration: BoxDecoration(
                                                            borderRadius: BorderRadius.all(Radius.circular(30))),
                                                        child:   TextField(
                                                          decoration: InputDecoration(
                                                            hintText: '请输入姓名或手机号',
                                                            hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.textColor),
                                                            filled: true,
                                                            fillColor: MyColors.backgreyColor,
                                                            border: InputBorder.none,
                                                            alignLabelWithHint: true,
                                                            // contentPadding: EdgeInsets.symmetric(vertical: 10.0.h, horizontal: 10.0.w),
                                                          ),
                                                          textAlign: TextAlign.left,
                                                          style: TextStyle(color: Colors.black),
                                                          onChanged: (value) {
                                                            setState(() {


                                                            });
                                                          },
                                                        ),
                                                      ),

                                                    ])
                                            ),
                                            Divider(height: 16.h,color: MyColors.backgreyColor,),
                                            Container(
                                                height: screenSize.height/2-100.h,
                                                child: ListView.builder(
                                                  shrinkWrap:false,
                                                  itemCount:scheduNameList.length,
                                                  itemBuilder: (BuildContext context, int index) {
                                                    return GestureDetector(
                                                      child:
                                                      Container(
                                                        child: Column(
                                                          children: [
                                                            Row(
                                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                              children: [
                                                                Text("王二二(18888888888)",style: TextStyle(color:schedulingIndex==index?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                                                                Text("剩余三次",style: TextStyle(color: schedulingIndex==index?MyColors.themeColor:Colors.black,fontSize: 14.sp),),
                                                              ],
                                                            ),

                                                            Divider(height: 16.h,color: MyColors.backgreyColor,),
                                                          ],
                                                        ),
                                                      ),
                                                      onTap: (){
                                                        setState(() {
                                                          schedulingIndex=index;
                                                        });
                                                        Navigator.pop(context);

                                                      },
                                                    );
                                                  },
                                                )
                                            ),
                                          ],
                                        )
                                    );
                                  }
                              );
                            },
                          ),
                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                          GestureDetector(
                            child:  Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Text("*",style: TextStyle(color: MyColors.themeColor),),
                                    Text("开单时间",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                  ],
                                ),
                                Row(
                                  children: [
                                    Text(startTime,style: TextStyle(color:startTime=="请选择"? MyColors.hintColor:Colors.black,fontSize: 14.sp),),
                                    SizedBox(width: 4.w,),
                                    Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                                  ],
                                ),
                              ],
                            ),
                            onTap: ()async{
                              final result=await showModalBottomSheet(context: context, builder: (BuildContext context) {
                                return chooseTimeSheet();
                              });
                              if (result!=null){
                                String mounth="";
                                String day="";
                                String hour ="";
                                String min ="";
                                setState(() {
                                  if(result[1].toString().length==1){
                                    mounth = result[1].toString().padLeft(2, '0');
                                  }else{
                                    mounth =result[1].toStringAsFixed(0);
                                  }
                                  if(result[2].toString().length==1){
                                    day = result[2].toString().padLeft(2, '0');
                                  }else{
                                    day =result[2].toStringAsFixed(0);
                                  }
                                  if(result[3].toString().length==1){
                                    hour = result[3].toString().padLeft(2, '0');
                                  }else{
                                    hour =result[3].toStringAsFixed(0);
                                  }
                                  if(result[4].toString().length==1){
                                    min = result[4].toString().padLeft(2, '0');
                                  }else{
                                    min =result[4].toStringAsFixed(0);
                                  }
                                  startTime=result[0].toString()+"-"+mounth+"-"+day+" "+hour+":"+min;
                                  print(startTime);
                                });

                              }
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(top: 10.h,right:7.w,left: 20.w,bottom: 10.h),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child:  GestureDetector(
                        child:  Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text("*",style: TextStyle(color: MyColors.themeColor),),
                                Text("项目",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              ],
                            ),
                            Row(
                              children: [
                                Text(projectName,style: TextStyle(color:projectName=="请选择项目名称"? MyColors.hintColor:Colors.black,fontSize: 14.sp),),
                                SizedBox(width: 4.w,),
                                Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                              ],
                            ),
                          ],
                        ),
                        onTap: ()async{
                          final result=await showModalBottomSheet(context: context, builder: (BuildContext context) {
                            return chooseOrganizationsheet( name: projectName,);
                          });
                          if (result!=null){
                            setState(() {
                              projectName=result[0];
                              projectMap=result[1];
                            });

                          }
                        },
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(top: 27.h,bottom: 27.h,left: 20.w,right: 7.w),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child: Column(
                        children: [
                          GestureDetector(
                            child:   Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height: 20.h,),
                                    SizedBox(width:13.w ,),
                                    Container(
                                      width: screenSize.width/1.5,
                                      child: Text(startAddressTwo=="请填写装货地详细地址"?startAddressTwo:"${startAddressList[10]}\n${startAddressList[3]}",style: TextStyle(color: startAddressTwo=="请填写装货地详细地址"?MyColors.hintColor:Colors.black,fontSize: 14.sp),),

                                    ),
                                  ],
                                ),
                                Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                              ],
                            ),
                          onTap: () async {
                            final result = await  Navigator.push( context, FadeRoute(page:TMSAddressSelection(addressType: 1, addressList: startAddressList,)));
                            if(result!=null){
                              setState(() {
                                startAddressList=result;
                                startAddressTwo=result[10];

                              });

                            }
                          },
                          ),
                          Divider(height: 34.h,color: MyColors.backgreyColor,),
                          GestureDetector(
                            child:   Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height: 20.h,),
                                    SizedBox(width:13.w ,),
                                    Container(
                                      width: screenSize.width/1.5,
                                      child: Text(endAddressTwo=="请填写卸货地详细地址"?endAddressTwo:"${endAddressList[10]}\n${endAddressList[3]}",style: TextStyle(color: endAddressTwo=="请填写卸货地详细地址"?MyColors.hintColor:Colors.black,fontSize: 14.sp),),

                                    ),                                  ],
                                ),
                                Icon(Icons.arrow_forward_ios,color: MyColors.hintColor,size: 20,),
                              ],
                            ),
                            onTap: () async {
                              final result = await  Navigator.push( context, FadeRoute(page:TMSAddressSelection(addressType: 2, addressList:endAddressList,)));
                              if(result!=null){
                                setState(() {
                                  endAddressList=result;
                                  endAddressTwo=result[10];
                                });
                              }
                            },
                          ),
                        ],
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 7.w,bottom: 10.h),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child:  Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text("*",style: TextStyle(color: MyColors.themeColor),),
                              Text("货物信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            ],
                          ),
                          GestureDetector(
                            child:    Row(
                              children: [
                                goodsMessageList[0]!=""?
                                Text(goodsMessageList[0][0],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                Text("必填，请输入货物信息",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                Icon(Icons.keyboard_arrow_right,color: MyColors.hintColor,),
                              ],
                            ),
                            onTap: ()async{
                              final result = await Navigator.push(
                                context,
                                goodsMessageList[0]!=""?
                                MaterialPageRoute(builder: (context) => CargoInformation(goodsName:goodsMessageList[0][1], packType: goodsMessageList[0][2], Weight:  goodsMessageList[0][3], Volume:  goodsMessageList[0][4], chooseType: 2, )) :
                                MaterialPageRoute(builder: (context) => CargoInformation(goodsName: '', packType: '', Weight: '', Volume: '', chooseType: 2, )),
                              );

                              // 在这里处理从下一个页面返回的值
                              if (result != null) {
                                print(result[0]);
                                setState(() {
                                  goodsMessageList[0]=result;

                                });
                              }
                            },
                          ),
                        ],
                      ),
                    ),
                    if(goodsMessageList[0]!="")
                    Container(
                      margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                      padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 7.w,bottom: 10.h),
                      decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.all(Radius.circular(10))),
                      child:  Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text(" ",style: TextStyle(color: MyColors.themeColor),),
                              Text("货物信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            ],
                          ),
                          GestureDetector(
                            child:    Row(
                              children: [
                                goodsMessageList[1]!=""?
                                Text(goodsMessageList[1][0],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                Text("请输入货物信息",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                goodsMessageList[1]!=""?
                                    GestureDetector(
                                      child: Icon(Icons.do_disturb_on_outlined,color: Colors.red,),
                                          onTap:(){
                                        setState(() {
                                          goodsMessageList[1]="";
                                        });
                                      }
                                    ):
                                Icon(Icons.keyboard_arrow_right,color: MyColors.hintColor,),

                              ],
                            ),
                            onTap: ()async{
                              final result = await Navigator.push(
                                context,
                                goodsMessageList[1]!=""?
                                MaterialPageRoute(builder: (context) => CargoInformation(goodsName:goodsMessageList[1][1], packType: goodsMessageList[1][2], Weight:  goodsMessageList[1][3], Volume:  goodsMessageList[1][4], chooseType: 2, )) :
                                MaterialPageRoute(builder: (context) => CargoInformation(goodsName: '', packType: '', Weight: '', Volume: '', chooseType: 2, )),
                              );

                              // 在这里处理从下一个页面返回的值
                              if (result != null) {
                                print(result[0]);
                                setState(() {
                                  goodsMessageList[1]=result;
                                  print(goodsMessageList[1]);

                                });
                              }
                            },
                          ),
                        ],
                      ),
                    ),
                    if(goodsMessageList[1]!="")
                      Container(
                        margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                        padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 7.w,bottom: 10.h),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(Radius.circular(10))),
                        child:  Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text(" ",style: TextStyle(color: MyColors.themeColor),),
                                Text("货物信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              ],
                            ),
                            GestureDetector(
                              child:    Row(
                                children: [
                                  goodsMessageList[2]!=""?
                                  Text(goodsMessageList[2][0],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                  Text("请输入货物信息",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                  goodsMessageList[2]!=""?
                                  GestureDetector(
                                      child: Icon(Icons.do_disturb_on_outlined,color: Colors.red,),
                                      onTap:(){
                                        setState(() {
                                          goodsMessageList[2]="";
                                        });
                                      }
                                  ):
                                  Icon(Icons.keyboard_arrow_right,color: MyColors.hintColor,),
                                ],
                              ),
                              onTap: ()async{
                                final result = await Navigator.push(
                                  context,
                                  goodsMessageList[2]!=""?
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName:goodsMessageList[2][1], packType: goodsMessageList[2][2], Weight:  goodsMessageList[2][3], Volume:  goodsMessageList[2][4], chooseType: 2, )) :
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName: '', packType: '', Weight: '', Volume: '', chooseType: 2, )),
                                );

                                // 在这里处理从下一个页面返回的值
                                if (result != null) {
                                  print(result[0]);
                                  setState(() {
                                    goodsMessageList[2]=result;
                                    print(goodsMessageList[2]);

                                  });
                                }
                              },
                            ),
                          ],
                        ),
                      ),
                    if(goodsMessageList[2]!="")
                      Container(
                        margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                        padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 7.w,bottom: 10.h),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(Radius.circular(10))),
                        child:  Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text(" ",style: TextStyle(color: MyColors.themeColor),),
                                Text("货物信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              ],
                            ),
                            GestureDetector(
                              child:    Row(
                                children: [
                                  goodsMessageList[3]!=""?
                                  Text(goodsMessageList[3][0],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                  Text("请输入货物信息",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                  goodsMessageList[3]!=""?
                                  GestureDetector(
                                      child: Icon(Icons.do_disturb_on_outlined,color: Colors.red,),
                                      onTap:(){
                                        setState(() {
                                          goodsMessageList[3]="";
                                        });
                                      }
                                  ):
                                  Icon(Icons.keyboard_arrow_right,color: MyColors.hintColor,),
                                ],
                              ),
                              onTap: ()async{
                                final result = await Navigator.push(
                                  context,
                                  goodsMessageList[3]!=""?
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName:goodsMessageList[3][1], packType: goodsMessageList[3][2], Weight:  goodsMessageList[3][3], Volume:  goodsMessageList[3][4], chooseType: 2, )) :
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName: '', packType: '', Weight: '', Volume: '', chooseType: 2, )),
                                );

                                // 在这里处理从下一个页面返回的值
                                if (result != null) {
                                  print(result[0]);
                                  setState(() {
                                    goodsMessageList[3]=result;
                                    print(goodsMessageList[3]);

                                  });
                                }
                              },
                            ),
                          ],
                        ),
                      ),
                    if(goodsMessageList[3]!="")
                      Container(
                        margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
                        padding: EdgeInsets.only(left: 20.w,top: 10.h,right: 7.w,bottom: 10.h),
                        decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.all(Radius.circular(10))),
                        child:  Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                Text(" ",style: TextStyle(color: MyColors.themeColor),),
                                Text("货物信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              ],
                            ),
                            GestureDetector(
                              child:    Row(
                                children: [
                                  goodsMessageList[4]!=""?
                                  Text(goodsMessageList[4][0],style: TextStyle(color: Colors.black,fontSize: 14.sp),):
                                  Text("请输入货物信息",style: TextStyle(color: MyColors.hintColor,fontSize: 14.sp),),
                                  goodsMessageList[4]!=""?
                                  GestureDetector(
                                      child: Icon(Icons.do_disturb_on_outlined,color: Colors.red,),
                                      onTap:(){
                                        setState(() {
                                          goodsMessageList[4]="";
                                        });
                                      }
                                  ):
                                  Icon(Icons.keyboard_arrow_right,color: MyColors.hintColor,),
                                ],
                              ),
                              onTap: ()async{
                                final result = await Navigator.push(
                                  context,
                                  goodsMessageList[4]!=""?
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName:goodsMessageList[4][1], packType: goodsMessageList[4][2], Weight:  goodsMessageList[4][3], Volume:  goodsMessageList[4][4], chooseType: 2, )) :
                                  MaterialPageRoute(builder: (context) => CargoInformation(goodsName: '', packType: '', Weight: '', Volume: '', chooseType: 2, )),
                                );

                                // 在这里处理从下一个页面返回的值
                                if (result != null) {
                                  print(result[0]);
                                  setState(() {
                                    goodsMessageList[4]=result;
                                    print(goodsMessageList[4]);
                                  });
                                }
                              },
                            ),
                          ],
                        ),
                      ),

                  ],
                ),
        ],
        ),
        ),
        Container(
          color: Colors.white,
          height: 80.h,
          padding: EdgeInsets.only(top: 10.h,right: 15.w,left: 15.w,bottom: 40.h),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [

              BrnSmallOutlineButton(
                title: '仅创建',
                lineColor: MyColors.themeColor,
                textColor: MyColors.themeColor,
                fontSize: 16.sp,
                fontWeight: FontWeight.w600,
                radius: 30,
                width: (screenSize.width-40.w)/3,
                onTap: () async {
                  print(goodsMessageList);
                  if (orderNum == "") {
                    BrnToast.show(
                      "请填写运单号", context, duration: BrnDuration.short,);
                  } else if (startTime == "") {
                    BrnToast.show(
                      "请添加开单时间", context, duration: BrnDuration.short,);
                  } else if (startAddressList.isEmpty) {
                    BrnToast.show("请添加装货地址信息", context,
                      duration: BrnDuration.short,);
                  } else if (endAddressList.isEmpty) {
                    BrnToast.show("请添加卸货地址信息", context,
                      duration: BrnDuration.short,);
                  } else if (goodsMessageList.isEmpty) {
                    BrnToast.show(
                      "请添加货物信息", context, duration: BrnDuration.short,);
                  } else {
                    String? shipperId = await UserIdManager.getUserID();
                    List cargoList=[ {
                      "id": goodsMessageList[0][1],
                      "name": goodsMessageList[0][1],
                      "type": goodsMessageList[0][5],
                      "packageType": goodsMessageList[0][2],
                      "weight": goodsMessageList[0][3],
                      "weightUnit": "T",
                      "volume": goodsMessageList[0][4],
                      "volumeUnit": "M3",
                      "number": goodsMessageList[0][6],
                      "numberUnit": "PIECE"
                    }];
                    if  (goodsMessageList[1]!=""){
                      cargoList.add( {
                        "id": goodsMessageList[1][1],
                        "name": goodsMessageList[1][1],
                        "type": goodsMessageList[1][5],
                        "packageType": goodsMessageList[1][2],
                        "weight": goodsMessageList[1][3],
                        "weightUnit": "T",
                        "volume": goodsMessageList[1][4],
                        "volumeUnit": "M3",
                        "number": goodsMessageList[1][6],
                        "numberUnit": "PIECE"
                      });
                    }
                    if  (goodsMessageList[2]!=""){
                      cargoList.add( {
                        "id": goodsMessageList[2][1],
                        "name": goodsMessageList[2][1],
                        "type": goodsMessageList[2][5],
                        "packageType": goodsMessageList[2][2],
                        "weight": goodsMessageList[2][3],
                        "weightUnit": "T",
                        "volume": goodsMessageList[2][4],
                        "volumeUnit": "M3",
                        "number":goodsMessageList[2][6],
                        "numberUnit": "PIECE"
                      });
                    }
                    if  (goodsMessageList[3]!=""){
                      cargoList.add( {
                        "id": goodsMessageList[3][1],
                        "name": goodsMessageList[3][1],
                        "type": goodsMessageList[3][5],
                        "packageType": goodsMessageList[3][2],
                        "weight": goodsMessageList[3][3],
                        "weightUnit": "T",
                        "volume": goodsMessageList[3][4],
                        "volumeUnit": "M3",
                        "number":goodsMessageList[3][6],
                        "numberUnit": "PIECE"
                      });
                    }
                    if  (goodsMessageList[4]!=""){
                      cargoList.add( {
                        "id": goodsMessageList[4][1],
                        "name": goodsMessageList[4][1],
                        "type": goodsMessageList[4][5],
                        "packageType": goodsMessageList[4][2],
                        "weight": goodsMessageList[4][3],
                        "weightUnit": "T",
                        "volume": goodsMessageList[4][4],
                        "volumeUnit": "M3",
                        "number":goodsMessageList[4][6],
                        "numberUnit": "PIECE"
                      });
                    }
                    print(startAddressList);
                    print(endAddressList);
                    ApiManager.postData(
                      context,
                      'api/tms/order/add',
                      {
                        "companyId": userInfo['companyInfo']['id'],
                        "orgId": userInfo['orgId'],
                        "shipperId": shipperId,
                        "sourceType": "INPUT",
                        "customerId": projectMap['companyId'],
                        "priceType": "FIXED",
                        "customerOrderNum": orderNum,
                        "customerLoadOrderNum": orderNum,
                        "customerOrderDate": startTime,
                        "distance": dintanceStr,
                        "consignorInfo": {
                          "id": userInfo['companyInfo']['id'],
                          "name": userInfo['companyInfo']['name'],
                          "category": "INDIVIDUAL",
                          "contact": startAddressList[4],
                          "phone": startAddressList[5],
                          "place": {
                            "provinceCode": startAddressList[2][0],
                            "cityCode": startAddressList[2][1],
                            "countyCode": startAddressList[2][2],
                            "province": startAddressList[1][0],
                            "city": startAddressList[1][1],
                            "county": startAddressList[1][2],
                            "address": startAddressList[3],
                            "longitude": startAddressList[9]['lng'],
                            "latitude": startAddressList[9]['lat']
                          }
                        },
                        "consignorIsNew": true,
                        "consigneeInfo": {
                          "id": projectMap['companyId'],
                          "name":  projectMap['name'],
                          "category": "INDIVIDUAL",
                          "contact": endAddressList[4],
                          "phone": endAddressList[5],
                          "place": {
                            "provinceCode": endAddressList[2][0],
                            "cityCode": endAddressList[2][1],
                            "countyCode": endAddressList[2][2],
                            "province": endAddressList[1][0],
                            "city": endAddressList[1][1],
                            "county": endAddressList[1][2],
                            "address": endAddressList[3],
                            "longitude": endAddressList[9]['lng'],
                            "latitude": endAddressList[9]['lat']
                          }
                        },
                        "consigneeIsNew": true,
                        "cargoInfo": cargoList,
                        "loadDay": "${DateTime.now().year}-${startAddressList[6]}",
                        "loadTime": startAddressList[7],
                        "unloadDay":"${DateTime.now().year}-${endAddressList[6]}",
                        "unloadTime": startAddressList[7],
                        "remark": ""
                      },
                          (responseData) {
                        BrnToast.show("创建成功", context, duration: BrnDuration
                            .short,);

                      },
                    );
                  }
                  }
                  ,

              ),
              SizedBox(width: 10.w,),
              BrnSmallMainButton(
                title: '创建并调度',
                textColor: Colors.white,
                fontSize: 14.sp,
                fontWeight: FontWeight.w600,
                radius: 30,
                width: (screenSize.width-40.w)/1.5,
                bgColor: MyColors.themeColor,

                onTap: () {
                  BrnToast.show('录需求信息', context);
                },
              )
            ],
          ),
        ),
      ],
    );
  }
}


class chooseOrganizationsheet extends StatefulWidget {
  const chooseOrganizationsheet({super.key, required this.name});
  final String name;
  @override
  State<chooseOrganizationsheet> createState() => _chooseOrganizationsheetState();
}

class _chooseOrganizationsheetState extends State<chooseOrganizationsheet> {
  List OrganizationList=[];
  int checkIndex=-1;
  int isDefault=0;
  String organizationName="";
  Map chooseMap={};
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    organizationName=widget.name;
    getOrgList();
  }


  Future<void> getOrgList() async {

    NoLoadinggetApiManager.getData(
      context,
      MyServiceUrl.getLoginUser,
      {},
          (responseData) async {
          Map companyInfo=responseData['data']['companyInfo'];
            NoLoadingApiManager.postData(
              context,
              'api/tms/customer/list',
              {
                "companyId": companyInfo['id'],
                "orgId": responseData['data']['orgId'],
                "customerId":"",
                "name": "",
                "shortName": ""
              },
                  (responseData) {
                setState(() {

                  OrganizationList=responseData['data'];
                });
              },
            );
      },
    );


  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Container(
      padding: EdgeInsets.only(top: 23.h,right:12.w,left: 23.w),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10))),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,

            children: [
              GestureDetector(
                child: Text("取消",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                onTap: (){
                  Navigator.pop(context);
                },
              ),
              Text("请选择运单所属项目",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
              Container(
                height: 25.h,
                child:   BrnSmallMainButton(
                  bgColor: MyColors.themeColor,
                  textColor: Colors.white,
                  radius: 30,
                  width: 56.w,
                  title: '确认',

                  onTap: () {
                    if(checkIndex!=-1)
                    Navigator.pop(context,[organizationName,chooseMap]);
                  },
                ),
              ),
            ],
          ),
          Divider(height: 16.h,color: MyColors.backgreyColor,),
          // Container(
          //   margin: EdgeInsets.only(top:20.h ),
          //   padding: EdgeInsets.only(left: 13.w),
          //   height: 36.h,
          //   decoration: BoxDecoration(
          //       color: MyColors.backgreyColor,
          //       borderRadius: BorderRadius.all(Radius.circular(10))),
          //   child: Row(
          //     crossAxisAlignment: CrossAxisAlignment.center,
          //     children: [
          //       Icon(Icons.search,color: MyColors.hintColor,),
          //       Container(
          //         padding: EdgeInsets.only(top: 9.h),
          //         width: screenSize.width-150.w,
          //         height: 30.h,
          //         child:  TextField(
          //           decoration: InputDecoration(
          //             hintText: '请输入组织名称进行查询',
          //             hintStyle:TextStyle(fontSize: 14.sp,color: MyColors.hintColor),
          //             filled: true,
          //             fillColor: MyColors.backgreyColor,
          //             border: InputBorder.none,
          //             alignLabelWithHint: true,
          //           ),
          //           textAlign: TextAlign.left,
          //
          //           style: TextStyle(color: Colors.black),
          //           onChanged: (value) {
          //             setState(() {
          //               print(value);
          //             });
          //           },
          //         ),
          //       ),
          //     ],
          //   ),
          // ),
          SizedBox(height: 20.h,),
          Container(
              height: OrganizationList.length*50.h,
               child: ListView.builder(  physics: NeverScrollableScrollPhysics(),
              shrinkWrap:false,
              itemCount: OrganizationList.length,
              itemBuilder: (BuildContext context, int index) {
                return GestureDetector(
                  child: Container(
                  height: 40.h,
                  width: screenSize.width,
                  padding: EdgeInsets.only(top: 10.h,bottom: 10.h),
                  child: Column(
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(OrganizationList[index]['projectName'],style: TextStyle(color:organizationName==OrganizationList[index]['projectName']?MyColors.themeColor: Colors.black,fontSize: 14.sp),),
                            // if(organizationName==OrganizationList[index]['name'])
                            //   GestureDetector(
                            //     child: Row(
                            //       children: [
                            //         isDefault==0?
                            //         Icon(Icons.radio_button_off,size: 20,color: MyColors.textColor,):
                            //         Icon(Icons.radio_button_on,size: 20,color: MyColors.themeColor,),
                            //         Text("设为默认",style: TextStyle(color: MyColors.textColor),),
                            //       ],
                            //     ),
                            //     onTap: (){
                            //       setState(() {
                            //         isDefault==0? isDefault=1: isDefault=0;
                            //       });
                            //     },
                            //   ),

                          ],
                        ),
                        if(index!= OrganizationList.length-1)
                        Divider(height: 1.h,color: MyColors.backgreyColor,),
                      ],
                    ),

                  ),
                  onTap: (){
                    setState(() {
                      organizationName=OrganizationList[index]["projectName"];
                      checkIndex=index;
                      chooseMap=OrganizationList[index];
                    });},
                );},),
          )
       
        ],
      ),
    );
  }
}

class settlementSheet extends StatefulWidget {
  const settlementSheet({super.key, required this.settlementStr});
  final String settlementStr;
  @override
  State<settlementSheet> createState() => _settlementSheetState();
}

class _settlementSheetState extends State<settlementSheet> {
  String name="";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    name=widget.settlementStr;
  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Container(
      height: 330.h,
      padding: EdgeInsets.only(top: 15.h),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10))),
      child: Column(
        children: [
          Text("请选择结算方式",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
          SizedBox(height: 20.h,),
          GestureDetector(
            child: Text("现付",style: TextStyle(color: name=="现付"?MyColors.themeColor:Colors.black),),
            onTap: (){
              setState(() {
                Navigator.pop(context,"现付");
              });
            },
          ),
          Divider(height: 30.h,color: MyColors.backgreyColor,),
          GestureDetector(
            child: Text("到付",style: TextStyle(color: name=="到付"?MyColors.themeColor:Colors.black),),
            onTap: (){
              setState(() {
                Navigator.pop(context,"到付");
              });
            },
          ),
          Divider(height: 30.h,color: MyColors.backgreyColor,),  GestureDetector(
            child: Text("回付",style: TextStyle(color: name=="回付"?MyColors.themeColor:Colors.black),),
            onTap: (){
              setState(() {
                Navigator.pop(context,"回付");
              });
            },
          ),
          Divider(height: 30.h,color: MyColors.backgreyColor,),
          GestureDetector(
            child: Text("月结",style: TextStyle(color: name=="月结"?MyColors.themeColor:Colors.black),),
            onTap: (){
              setState(() {
                Navigator.pop(context,"月结");
              });
            },
          ),
          SizedBox(height: 15.h,),
          Container(
            height: 8.h,
            width: screenSize.width,
            color: MyColors.backgreyColor,
          ),
          SizedBox(height: 15.h,),
          GestureDetector(
            child: Text("取消",style: TextStyle(color: Colors.black),),
            onTap: (){
            Navigator.pop(context);
            },
          ),
        ],
      ),
    );
  }
}

class chooseTimeSheet extends StatefulWidget {
  const chooseTimeSheet({super.key,});

  @override
  State<chooseTimeSheet> createState() => _chooseTimeSheetState();
}

class _chooseTimeSheetState extends State<chooseTimeSheet> {
  DateTime selectedDate = DateTime.now();
  int selectedYear = DateTime.now().year;
  int selectedMonth = DateTime.now().month;
  int selectedDay = DateTime.now().day;
  int selectedHour = DateTime.now().hour;
  int selectedMinute = DateTime.now().minute;
  late List<int> years;
  late FixedExtentScrollController yearController;
  late FixedExtentScrollController monthController;
  late FixedExtentScrollController dayController;
  late FixedExtentScrollController hourController;
  late FixedExtentScrollController minuteController;
  @override
  void initState() {
    super.initState();

    DateTime selectedDate = DateTime.now();
    int selectedYear = DateTime.now().year;
    int selectedMonth = DateTime.now().month;
    int selectedDay = DateTime.now().day;
    int selectedHour = DateTime.now().hour;
    int currentYear = DateTime.now().year;
    int currentMinute = DateTime.now().minute;
    years = List.generate(6, (index) => currentYear + index);
    // 设置初始滚动位置
    yearController = FixedExtentScrollController(initialItem: years.indexOf(selectedYear));
    monthController = FixedExtentScrollController(initialItem: selectedMonth - 1);
    dayController = FixedExtentScrollController(initialItem: selectedDay - 1);
    hourController = FixedExtentScrollController(initialItem: selectedHour);
    minuteController = FixedExtentScrollController(initialItem: selectedMinute);
  }
  @override
  int getDaysInMonth(int year, int month) {
    return DateTime(year, month + 1, 0).day;
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 280.h,
      padding: EdgeInsets.only(top: 23.h,right:12.w,left: 23.w),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.all(Radius.circular(10))),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,

            children: [
              GestureDetector(
                child: Text("取消",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                onTap: (){
                  Navigator.pop(context);
                },
              ),
              Text("请选择开单时间",style: TextStyle(color: Colors.black,fontSize: 16.sp,fontWeight: FontWeight.w600),),
              Container(
                height: 25.h,
                child:   BrnSmallMainButton(
                  bgColor: MyColors.themeColor,
                  textColor: Colors.white,
                  radius: 30,
                  width: 56.w,
                  title: '确认',
                  onTap: () {
                    Navigator.pop(context,[selectedYear,selectedMonth,selectedDay,selectedHour,selectedMinute]);
                  },
                ),
              ),
            ],
          ),
          Divider(height: 30.h,color: MyColors.backgreyColor,),
          Text("时间格式:年-月-日 时:分",style: TextStyle(color: Colors.black),),
          SizedBox(height: 4.h,),
          Container(
            decoration: BoxDecoration(
              border: Border.all(
                color: Color.fromRGBO(224, 227, 234, 1),
                width: 1,
              ),
              borderRadius: BorderRadius.circular(5.0), // 可选，添加圆角
            ),
            child:  Row(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                _buildPicker(
                  items: generateYearList(),
                  controller: yearController,
                  onChanged: (value) {
                    setState(() {
                      selectedYear = value;
                    });
                  },
                ),
                _buildPicker(
                  items: List.generate(12, (index) => index + 1),
                  controller: monthController,
                  onChanged: (value) {
                    setState(() {
                      selectedMonth = value;
                    });
                  },
                ),
                _buildPicker(
                  items: List.generate(getDaysInMonth(selectedYear, selectedMonth), (index) => index + 1),
                  controller: dayController,
                  onChanged: (value) {
                    setState(() {
                      selectedDay = value;
                    });
                  },
                ),
                _buildPicker(
                  items: List.generate(24, (index) => index),
                  controller: hourController,
                  onChanged: (value) {
                    setState(() {
                      selectedHour = value;
                    });
                  },
                ),
                _buildPicker(
                  items: List.generate(24, (index) => index),
                  controller: minuteController,
                  onChanged: (value) {
                    setState(() {
                      selectedMinute = value;
                    });
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
  Widget _buildPicker({
    required List<int> items,
    required FixedExtentScrollController controller,
    required ValueChanged<int> onChanged,
  }) {
    return Container(
      height: 150.0,
      width: 50.0,
      child: CupertinoPicker(
        itemExtent: 40.0,
        onSelectedItemChanged: (index) {
          onChanged(items[index]);
        },
        selectionOverlay: _buildSelectionOverlay(),
        children: items.map((item) => _buildPickerItem(item)).toList(),
        // 使用初始化的控制器
        scrollController: controller,
      ),
    );
  }

  Widget _buildPickerItem(int item) {
    // 将月份和日期格式化为两位数
    String formattedItem = item.toString().padLeft(2, '0');

    return Container(
      alignment: Alignment.center,
      child: Text(formattedItem),
    );
  }

  Widget _buildSelectionOverlay() {
    return Container(
      height: 40.0,
      decoration: BoxDecoration(
        border: Border(
          top: BorderSide(color: Color.fromRGBO(220, 224, 231, 1), width: 1.0.h),
          bottom: BorderSide(color: Color.fromRGBO(220, 224, 231, 1), width: 1.0.h),
        ),
      ),
    );
  }

  // 生成年份列表，包括当前年份和之后的5年
  List<int> generateYearList() {
    int currentYear = DateTime.now().year;
    List<int> years = List.generate(6, (index) => currentYear + index);
    return years;
  }
}
